Skip to content

Conversation

angelosilvestre
Copy link

@angelosilvestre angelosilvestre commented Jul 11, 2025

Add support for variable page sizes. (Resolves #59)

Currently, the PageListViewport widget assumes that all pages have the same natural size.

This PR adds an option to have pages with different sizes. To do that, the existing PageListViewport was split into two widgets, one for fixed-size pages and other for variable-sized pages. I copied the original widget and made the adjustments to work with variable page sizes. To make the gestures work with both widgets, I had to create an abstract class PageListViewportLayout, that exposes the methods needed for the controller and gesture widgets to query the necessary information.

This PR also adds widget tests and golden tests.

variable_page_layout.mp4

@angelosilvestre angelosilvestre changed the title Add support for variable page sizes. (Resolves #59) WIP: Add support for variable page sizes. (Resolves #59) Jul 11, 2025
PageListViewportGestures(
controller: _controller,
lockPanAxis: true,
child: PageListViewport.variedPageSized(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dodgog I'm reviewing this PR with @angelosilvestre - what do you think about this widget API? Do you see anything missing in terms of what you need for varied page sizes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, yes. I can see the alternative being: passing a list of page sizes and also a function onGetNaturalSizeForPage() [doesn't have arguments]. Or is there a design constraint requiring onGetNaturalPageSize to be a different function for each page?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dodgog

A list of page sizes sounds good to me, but I didn't understand why we would have an onGetNaturalSizeForPage() without arguments if the list of page sizes is provided.

Could you clarify that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api looks good. It's either a list of sizes, or a PageSizeResolver with a cache.
It may not always be cheap to obtain a list of sizes in advance, that's why onGetSize can be helpful to dynamically build the viewport.

Just to confirm my understanding: does the total length of the viewport need to be known in advance in order to render the widget?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api looks good. It's either a list of sizes, or a PageSizeResolver with a cache.
It may not always be cheap to obtain a list of sizes in advance, that's why onGetSize can be helpful to dynamically build the viewport.

Currently, only a PageSizeResolver is allowed. Do you want another option to give a list of sizes instead?

Just to confirm my understanding: does the total length of the viewport need to be known in advance in order to render the widget?

The pageCount is required in order to render the widget.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no need for a list of sizes. The consumer of the api could probably implement a convenience resolver which would have cached values, for example a getSize(i) function which would map to sizesList[i] as you do in the example app roughly. This is good for now. Can proceed with final reviews and merging probably.

Let's not act on this now, but I'm wondering if it will be easy/worth it to make the calculation and per-page layout lazy? Would have to involve some complex scrolling approximations, but how hard is it?

@angelosilvestre angelosilvestre marked this pull request as ready for review July 19, 2025 19:17
@angelosilvestre angelosilvestre changed the title WIP: Add support for variable page sizes. (Resolves #59) Add support for variable page sizes. (Resolves #59) Jul 26, 2025
@matthew-carroll
Copy link
Contributor

@angelosilvestre can you coordinate with @dodgog until you two have explicit agreement about the public API in this PR? I probably should spend time reviewing the implementation until we have a good API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arbitrary document page aspect ratios
3 participants